package com.weige.conver.service;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.weige.conver.utils.FileUtils;
import com.weige.conver.utils.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@Component
@EnableScheduling
@Slf4j
public class ConfigService {

    /**
     * 定时获取type.json数据
     */
    public Map<String, String> getTypeData() {
        JSONObject typeData = typeData();
        Map<String, String> typeMap = JSONObject.parseObject(typeData.toJSONString(), new TypeReference<Map<String, String>>() {
        });
        return typeMap;
    }

    public JSONObject typeData() {
        JSONObject typeData = new JSONObject();
        typeData.put("0", "温湿度传感器");
        typeData.put("1", "水浸传感器");
        typeData.put("2", "烟雾传感器");
        typeData.put("3", "氧气含量测量传感器");
        typeData.put("4", "SF6气体含量测量传感器");
        typeData.put("5", "电子围栏状态监测");
        typeData.put("6", "门禁状态监测");
        typeData.put("7", "其他状态");
        typeData.put("8", "风速传感器");
        typeData.put("9", "控制器状态监测");
        typeData.put("10", "SF6设备状态监测");
        typeData.put("11", "液位压力监测器");
        typeData.put("12", "氧气气体报警器");
        typeData.put("13", "开关柜位类型");
        typeData.put("14", "开关柜电源状态");
        typeData.put("15", "开关柜摄像头状态");
        typeData.put("16", "开关柜设备状态");
        typeData.put("17", "开关柜设备告警");
        typeData.put("18", "开关柜报告");
        typeData.put("19", "开关柜软压板");
        typeData.put("20", "开关柜监测数据");
        typeData.put("21", "消防安全告警器");
        typeData.put("22", "油位传感器");
        typeData.put("23", "气体压力测量传感器");
        typeData.put("24", "气体密度测量传感器");
        typeData.put("25", "水浸告警器");
        typeData.put("41", "红外探测器");
        typeData.put("42", "时控天数代码");
        typeData.put("43", "标志寄存器");
        return typeData;
    }


    /**
     * 定时获取data.json数据
     */
    public Map<String,String> getConfigData() {
        JSONObject data = configData();
        Map<String, String> dataMap = JSONObject.parseObject(data.toJSONString(), new TypeReference<Map<String, String>>() {
        });
        return dataMap;
    }

    public JSONObject configData() {
        JSONObject configData = new JSONObject();
        configData.put("ID", "devId");
        configData.put("Name", "devName");
        configData.put("Value", "sigValue");
        configData.put("IotType", "type");
        configData.put("ValueDesc", "sigDescription");
        return configData;
    }

    /**
     * 定时获取site.txt数据
     *
     * @throws IOException
     */
    public Map<String,String> getResouceData(){
        Map<String,String> siteMap = new HashMap<>();
        siteMap.put("siteId", "44010102192000000011");
        siteMap.put("siteName", "110kV光谱站");
        return siteMap;
    }
}
